<?php
namespace Admin\Controller;
use Think\Controller;
class HotcarController extends PublicController{
	public function index(){
	 	 $re=M('car_type')->select();
	 	 $this->cartype=$re;
		 $this->display();
	 } 
	

	//获取热门车型信息
	public function get_hotcar_list(){
	 	$limit = I('get.limit');
	    $page = I('get.page');
	    $like = I('get.like');
	    if($like!=""){
	    	$where="a.car_type_id like '%".$like."%' or b.name like '%".$like."%'";
	    }
	 	$ret['total']=M('hotcar')->count();
	 	$ret['data']=M('hotcar')->alias('a')
	 	->field('a.id,a.car_type_id,b.logo,b.name')
	 	->join('__CAR_TYPE__ as b on a.car_type_id=b.id')
	 	->where($where)
	 	->select();
	 	foreach ($ret['data'] as $key => $value) {
	 		$ret['data'][$key]['logo']='<img style="width:50px;" src="'.$ret['data'][$key]['logo'].'">';
	 	}
	 	$ret['code']=200;
	 	$ret['msg']="查询成功";
	 	ret($ret);

	 }
 
	//编辑热门品牌提交
	public function update(){
	 	$id=I('post.id');
	 	$data['car_type_id']=I('post.cartypeid');
	 	$re=M('hotcar')->where(['id'=>$id])->save($data);
	 	if($re){
	 		$ret['code']=200;
	 		$ret['msg']="修改成功";
	 		ret($ret);
	 	}else{
	 		$ret['code']=400;
	 		$ret['msg']="修改失败";
	 		ret($ret);
	 	}
	}
	 //删除热门品牌
	public function del(){
      $data['id']=I('post.id');
      $re=M('hotcar')->where('id='.$data['id'])->delete();
      if($re){
        $ret['isSuccess']=1;
        $ret['msg']="删除成功";
        ret($ret);
      }else{
        $ret['isSuccess']=0;
        $ret['msg']="删除失败";
        ret($ret); 
      }
    }
}
